#include<stdio.h>

struct Rational
{
    int numerato;
    int denominator;
};

struct Rational make_rational(int a, int b)
{
    struct Rational r;

    if (b)
    {
        r.numerato = a;
        r.denominator = b;
    }
    else
    {
        printf("error input, denominator can not be zero!");
    }

    return r;

}

int get_numerato(struct Rational a)
{
    return a.numerato;
}

int get_denominator(struct Rational a)
{
    return a.denominator;
}

struct Rational add_rational(struct Rational a, struct Rational b)
{
    return make_rational(get_numerato(a) * get_denominator(b) + get_numerato(b) * get_denominator(a), get_denominator(a) * get_denominator(b));
}

struct Rational sub_rational(struct Rational a, struct Rational b)
{
    return make_rational(get_numerato(a) * get_denominator(b) - get_numerato(b) * get_denominator(a), get_denominator(a) * get_denominator(b));
}

struct Rational mul_rational(struct Rational a, struct Rational b)
{
    return make_rational(get_numerato(a) * get_numerato(b) , get_denominator(a) * get_denominator(b));
}

struct Rational div_rational(struct Rational a, struct Rational b)
{
    if (get_numerato(b))
        return make_rational(get_numerato(a) * get_denominator(b), get_denominator(a) * get_numerato(b));
    else
        printf("error input, denominator can not be zero!");
    //return make_rational(0, 1);
        
}

int return_GCD(int a, int b)
{
    if (!(a % b))
    {
        return b > 0 ? b : -b;
    }
    else
    {
        int tmp = a;
        a = b;
        b = tmp % b;
        return_GCD(a, b);
    }
}

void print_rational(struct Rational a)
{
    int gcd = return_GCD(get_numerato(a), get_denominator(a));
    
    if (get_numerato(a) * get_denominator(a) > 0)
        printf("%d / %d\n", get_numerato(a)/gcd, get_denominator(a)/gcd);
    else if (get_numerato(a) == 0)
        printf("0\n");
    else
    {
        printf("-%d / %d\n", get_numerato(a)/gcd >= 0 ? get_numerato(a)/gcd : get_numerato(a)/gcd * -1, get_denominator(a)/gcd >= 0 ? get_denominator(a)/gcd : get_denominator(a)/gcd * -1);
    }

}

int main()
{
    struct Rational a = make_rational(1, -8);
    struct Rational b = make_rational(0, 8);
    print_rational(add_rational(a, b));
    print_rational(sub_rational(a, b));
    print_rational(mul_rational(a, b));
    print_rational(div_rational(a, b));

    return 0;
}

